package com.syni.mdd.yhd.common.all.utils.aurora;

import cn.jiguang.common.utils.Base64;
import com.syni.mdd.yhd.common.all.config.AuroraConfig;
import com.syni.mdd.yhd.common.all.utils.RestTemplateUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.AppConfig;
import org.springframework.http.HttpMethod;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @className CustomClient
 * @description TOO
 * @Author cfx
 * @DATE 2019/10/26 15:54
 * @VERSION 1.0
 **/
public class CustomClient {

    public static String getAuthCode(Integer roleId){
        String USER_APP_KEY = "";
        String USER_MASTER_SECRET = "";
        /*if (roleId == Constants.GENERAL_USER_ROLE_ID) {
            USER_APP_KEY = AuroraConfig.USER_APP_KEY_1;
            USER_MASTER_SECRET = AuroraConfig.USER_MASTER_SECRET_1;
        } else if (roleId == Constants.BUSINESS_ROLE_ID || roleId == Constants.ASSISTANT_ROLE_ID) {
            USER_APP_KEY = AuroraConfig.BUSINESS_APP_KEY_1;
            USER_MASTER_SECRET = AuroraConfig.BUSINESS_MASTER_SECRET_1;
        }*/
        USER_APP_KEY = AppConfig.getProperty(AuroraConfig.USER_APP_KEY);
        USER_MASTER_SECRET = AppConfig.getProperty(AuroraConfig.USER_MASTER_SECRET);
        String encodeKey = USER_APP_KEY + ":" + USER_MASTER_SECRET;
        return "Basic " + String.valueOf(Base64.encode(encodeKey.getBytes()));
    }

    public static String bannerUserInGroup(String bannerUser,Integer bannerUserRole, String gid,String bannerStatus){
        String url = String.format("%s/groups/messages/%s/silence?status=%s", AuroraConfig.CUSTOM_CLIENT_URL,gid,bannerStatus);
        Map<String,Object> headerMap = new HashMap<>();
        headerMap.put("Authorization",getAuthCode(bannerUserRole));
        List<String> params = new ArrayList<>();
        params.add(bannerUser);
        return RestTemplateUtils.postForEntityForJson(url, HttpMethod.PUT,headerMap,params);
    }
}
